<?php
/**
 * Created by PhpStorm.
 * User: Dell
 * Date: 2019-3-25
 * Time: 14:12
 */

namespace app\index\controller;


use org\Verify;
use sms\SignatureHelper;
use think\Controller;
use think\Session;

class Sms extends Controller
{
    /**
     * 发送阿里大鱼短信接口
     * @return \think\response\Json
     */
    public function index(){
        if (request()->isAjax()){
            $phone = input("param.phone");
            $code = input("param.code");

            $verify = new Verify();
            if (!$verify->check($code)) {
                return json(msg(-2, '', '验证码错误'));
            }
                $sms = new SignatureHelper();
                $param['rand'] = rand(100000,999999);
                $param['name'] = "附城花椒";
                $param['template'] = "SMS_163057683";
                $param['phone'] = $phone;
                Session::set('Pcode',$param['rand']);
                $result = $sms->sendSms('LTAIDtoWjVf1Lnhg','EcinaJakMiBPAc9GxS2QAy8yhQdeRW',$param);
                return json(msg(1,'',$result));
            }
    }

    // 验证码
    public function checkVerify()
    {
        $verify = new Verify();
        $verify->imageH = 32;
        $verify->imageW = 100;
        $verify->length = 4;
        $verify->useNoise = false;
        $verify->fontSize = 14;
        return $verify->entry();
    }
}